#!/usr/bin/env python
# coding=utf-8

import RPi.GPIO as GPIO

from plant import logger


# relay sv
class RelaySV(object):

    def __init__(self, pin):
        self.pin = pin
        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BCM)

    def on(self):
        '''
        relay on
        :return:
        '''
        logger.info('The pin ' + str(self.pin) + ' ON')
        GPIO.setup(self.pin, GPIO.OUT)
        GPIO.output(self.pin, GPIO.HIGH)

    def off(self):
        '''
        relay off
        :return:
        '''
        logger.info('The pin ' + str(self.pin) + ' OFF')
        GPIO.setup(self.pin, GPIO.OUT)
        GPIO.output(self.pin, GPIO.LOW)
